<?php
namespace Admin\Controller;

use Think\Controller;

class PublicController extends AdminBaseController
{
    public function  test()
    {
        $moduleDir = APP_PATH . MODULE_NAME . DIRECTORY_SEPARATOR;
        $moduleEvent = A('Scan', 'Event');
        $rst = $moduleEvent->scan($moduleDir);
        print_g($rst);
    }

    public function login()
    {
        if (IS_POST) {
            $uname = I('post.username');
            $upass = I('post.password');
            if (!empty($uname) && !empty($upass)) {

                $adminModel = D('Admin');
                $rst = $adminModel->login($uname, $upass);
                $this->ajaxReturn($rst);

            } else {
                exit(json_encode(array('status' => 0, 'msg' => '请填写账号密码')));
            }
        } else {

            $this->_display('login', '登录页面');
        }

    }

    public function logout()
    {
        $adminModel = D('Admin');
        $adminModel->logout();
        $this->redirect('Public/login');
    }

    public function setPass()
    {

        $adminModel = D('Admin');
        return $adminModel->setPass('uname = "admin"', 'admin');
    }
}